package com.lc.pianostudent.conn;


import com.lc.pianostudent.bean.ContactBean;
import com.lc.pianostudent.bean.ContactListBean;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/2/22.
 */
@HttpInlet(Conn.GETMAIL)
public class PostGetmail extends BaseAsyPost {

    public String id;
    public String type;
    public PostGetmail(AsyCallBack asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected PostGetmailInfo parser(JSONObject object) throws Exception {
        if (object.optString("code").equals("200")) {

            PostGetmailInfo info = new PostGetmailInfo();

            info.code = object.optString("code");

            JSONArray array = object.optJSONArray("list");

            for (int j = 0;j<array.length();j++) {
                ContactBean contactBean = new ContactBean();
                JSONObject jb = array.optJSONObject(j);
                String letter = jb.optString("letter");
                contactBean.setLetter(letter);

                JSONArray jsonArray = jb.getJSONArray("list");
                List<ContactListBean> contactListBeanList = new ArrayList<ContactListBean>();
                for (int z = 0; z < jsonArray.length(); z++) {
                    ContactListBean bean = new ContactListBean();
                    JSONObject jObject = jsonArray.optJSONObject(z);
                    bean.setPerson(jObject.optString("person"));
                    bean.setName(jObject.optString("name"));
                    bean.setCname(jObject.optString("cname"));
                    bean.setAvatar(jObject.optString("avatar"));
                    bean.setCharm(jObject.optString("charm"));
                    bean.setId(jObject.optString("id"));
                    contactListBeanList.add(bean);
                }
                contactBean.setContact_list(contactListBeanList);
                info.contactList.add(contactBean);
            }
            TOAST = object.optString("message");
            return info;

        } else {

            TOAST = object.optString("message");

        }

        return null;
    }

    public static class PostGetmailInfo {

        public String code, message;
        public List<ContactBean> contactList = new ArrayList<>();

    }

}
